<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="原因" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['theReason']" :trigger-change="true" dictCode="st_status" placeholder="请选择原因"/>
        </a-form-item>
        <a-form-item label="离校时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择离校时间" v-decorator="[ 'departureTime', validatorRules.departureTime]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['fieldOne']" :trigger-change="true"/>
        </a-form-item>
        <a-form-item label="审批人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-select-user-by-dep-i-d v-decorator="['approver']" :trigger-change="true"/>
        </a-form-item>
        <a-form-item label="归校时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择归校时间" v-decorator="[ 'backTime']" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="确认人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-select-user-by-dep-i-d v-decorator="['confirmor']" :trigger-change="true"/>
        </a-form-item>
        <a-form-item label="确认时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择确认时间" v-decorator="[ 'confirmTime', validatorRules.confirmTime]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  import JSelectUserByDepID from '@/components/jeecgbiz/JSelectUserByDepID'
  import JSearchSelectTag from "@/components/dict/JSearchSelectTag"
  import JInput from "../../../components/jeecg/JInput";

  export default {
    name: "updateStatus",
    components: {
      JInput,
      JDate,
      JSelectUserByDepID,
      JSearchSelectTag,
    },

    data () {
      return {
        stName:"",
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        stuIds:"",
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules:{
        theReason:{rules: [{ required: true, message: '请输入原因!' }]},
        departureTime:{rules: [{ required: true, message: '请输入离校时间!' }]},
        approver:{rules: [{ required: true, message: '请输入审批人!' }]},
        backTime:{rules: [{ required: true, message: '请输入归校时间!' }]},
        confirmor:{},
        confirmTime:{},
        },
        url: {
          updateStatus: "/st/mobile/updateStatus",
        }
     
      }
    },
    created () {
    },  mounted () {
    },
    methods: {
      updateStatus (stuIds) {
        this.form.resetFields();
        this.visible = true;
        this.stuIds=stuIds
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = 'post';
            httpurl+=this.url.updateStatus;
            let formData = Object.assign(this.model, values);
           formData["stuIds"]=that.stuIds;
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'stuIds','theReason','departureTime','approver','backTime','confirmor','confirmTime'))
      },

      
    }
  }
</script>